﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Employees;

namespace Companies
{
   public class ChangeCompany
    {
       
        public  List<Company> companies= new List<Company>();

        public void AddCompany(string companyCode, string companyDescription)
        {
            
            //TODO: anunta daca a fost vre-o eroare la adaugarea companiilor --> Exceptie

          Company company = new Company(companyCode, companyDescription);
           
          foreach (Company _company in companies)
          {
              try
              {
                  if (_company.CompanyCode != companyCode)
                      companies.Add(company);
              }
              catch { }
          }

          //var c = companies.FirstOrDefault(c => c.CompanyCode == companyCode);
          //if (c == null)
          //{
          //    companies.Add(company);
          //}

        }

        public void RemoveCompany(string companyCode)
        {
            foreach (Company company in companies)
            {
                if (company.CompanyCode == companyCode)
                {
                    companies.Remove(company);
                    break;
                }
                    
            } 
                
        }

        public void ChangeCompanyCode(string newCompanyCode)
        {
            var company = companies.FirstOrDefault(c => c.CompanyCode == CompanyId);
            if (company != null)
            {
                foreach (Company _company in companies)
                {
                    if (_company.CompanyCode != newCompanyCode)
                        _company.CompanyCode = newCompanyCode;
                }
            }
        }

        public void ChangeCompanydescription(int companyId, string newCompanyDescription)
        {
            var company = companies.FirstOrDefault(c => c.CompanyId == companyId);
            if (company != null)
            {
                company.CompanyDescription = newCompanyDescription;
            }
        }

    }
}
